import { Controller, Post, Body } from '@nestjs/common';
import { AuthService } from './auth.service';
import { ApiResponse } from '../../common/response';
import { RegisterDto } from './dto/register.dto';
import { LoginVO } from './vo/login.vo';
import { LoginDto } from './dto/login.dto';
import {
  ApiTags,
  ApiOperation,
  ApiResponse as ApiSwaggerResponse,
} from '@nestjs/swagger';

@ApiTags('认证')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @ApiOperation({ summary: '用户注册' })
  @ApiSwaggerResponse({
    status: 200,
    description: '注册成功',
    type: LoginVO,
  })
  @Post('register')
  async register(@Body() body: RegisterDto): Promise<ApiResponse<LoginVO>> {
    const result = await this.authService.register(body);
    return ApiResponse.success(result, '注册成功');
  }

  @ApiOperation({ summary: '用户登录' })
  @ApiSwaggerResponse({
    status: 200,
    description: '登录成功',
    type: LoginVO,
  })
  @Post('login')
  async login(@Body() body: LoginDto): Promise<ApiResponse<LoginVO>> {
    const result = await this.authService.login(body);
    return ApiResponse.success(result, '登录成功');
  }
}
